package g4p.styledtext;

import g4p_controls.G4P;
import g4p_controls.GButton;
import g4p_controls.GCScheme;
import g4p_controls.GEvent;
import g4p_controls.GLabel;
import g4p_controls.GTextArea;

import java.awt.Color; // needed for Color class

import processing.core.PApplet;

public class LineAtTest extends PApplet {


	GTextArea textarea1; 
	GLabel label1; 
	GButton button1; 

	int lineNo = 0;
	String[] lines;

	public void setup() {
		size(450, 260, JAVA2D);
		createGUI();
		customGUI();
	}

	public void draw() {
		background(255, 255, 240);
	}

	public void customGUI() {
		// Add some dummy text to the text area
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 15; i++) {
			sb.append("Line ----   " + i + "  ----\n");
//			sb.append("Line ----   " + i + "  ---- Peter Lager lives in Rhyl North Wales\n");
		}
		textarea1.setText(sb.toString(), 5000);
		textarea1.moveCaretTo(0, 0);
		lines = textarea1.getTextAsArray();
	}

	public void button1_click1(GButton source, GEvent event) {
		if (lineNo >=0 && lineNo < lines.length - 1) {
			textarea1.clearStyles(lineNo);
			lineNo++;
			label1.setText("#>" + textarea1.getText(lineNo) + "<#");
			textarea1.addStyle(G4P.BACKGROUND, new Color(200, 200, 128), lineNo, 0, lines[lineNo].length());
			textarea1.moveCaretTo(lineNo, 0);
		}
	}

	public void createGUI() {
		G4P.messagesEnabled(false);
		G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
		G4P.setCursor(ARROW);
		if (frame != null)
			frame.setTitle("Sketch Window");
		textarea1 = new GTextArea(this, 10, 50, 200, 200, G4P.SCROLLBARS_BOTH);
		textarea1.setOpaque(true);
		label1 = new GLabel(this, 220, 20, 220, 60);
		label1.setText("My label");
		label1.setOpaque(true);
		button1 = new GButton(this, 10, 20, 200, 20);
		button1.setText("Next Line");
		button1.setTextBold();
		button1.addEventHandler(this, "button1_click1");
	}


}
